package com.woniu.cms.auth.core.controller;


import com.woniu.cms.auth.core.entity.Company;
import com.woniu.cms.auth.core.entity.Position;
import com.woniu.cms.auth.core.service.ICompanyService;
import com.woniu.cms.auth.core.service.IPositionService;
import com.woniu.cms.auth.core.vo.PositionVo;
import com.woniu.common.api.Result;
import com.woniu.common.feign.AuthClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lilili
 * @since 2022-09-16
 */
@RestController
@RequestMapping("/position")
@Api(tags="职位控制器")
public class PositionController {
    @Resource
    private IPositionService positionService;


    /**
     * 查找所有
     *
     * @return {@link Result}<{@link List}<{@link Company}>>
     */
    @GetMapping
    @ApiOperation("获取所有职位")
    public Result<List<PositionVo>> findAll(){
        List<PositionVo> list = positionService.getAll();
        return Result.common(list);
    }


    /**
     * 提交
     *
     * @param positionName 职位名称
     * @param companyName  公司名称
     * @return {@link Result}<{@link Object}>
     */
    @PostMapping("/{positionName}/{companyName}")
    @ApiOperation("添加职位")
    public Result<Object> commit(@PathVariable("positionName") String positionName, @PathVariable("companyName") String companyName){
        Boolean save = positionService.commit(positionName, companyName);

        return Result.common(save);
    }


    /**
     * 更新
     *
     * @param positionVo 签证官位置
     * @return {@link Result}<{@link Object}>
     */
    @PutMapping
    @ApiOperation("更新职位")
    public Result<Object> update(@RequestBody PositionVo positionVo){
        boolean b = positionService.updatePosition(positionVo);
        return Result.common(b);
    }

    /**
     * 删除
     *
     * @param id id
     * @return {@link Result}<{@link Object}>
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除职位")
    public Result<Object> delete(@PathVariable("id") Integer id){
        boolean b = positionService.removePosition(id);
        return Result.common(b);
    }


    @ApiOperation("获取指定职位名称的用户名称组")
    @GetMapping("/getUser/{name}")
    public Result<List<String>> getUserByPositionName(@PathVariable("name") String name){
        List<String> names = positionService.getUserByPositionName(name);
        return Result.common(names);
    }

    /**
     * 根据职位名称获取所有用户id
     *
     * @param name 名字
     * @return {@link Result}<{@link Object}>
     */
    @ApiOperation("根据职位名称获取所有用户id")
    @GetMapping("/getUserId/{name}")
    public Result<List<Integer>> getUserIdByPositionName(@PathVariable("name") String name){
        List<Integer> userIds = positionService.getUserIdByPositionName(name);
        return Result.common(userIds);
    }
}

